<?php

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Models\CaseCenter;

class CaseCenterController extends Controller
{
    use ModelForm;
    public function index()
    {
        return Admin::content(function (Content $content) {
            $content->header('案例中心');
            $content->description('管理');
            $content->body($this->grid());
        });
    }

    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {
            $content->header('案例中心');
            $content->description('编辑');

            $content->body($this->form()->edit($id));
        });
    }

    public function create()
    {
        return Admin::content(function (Content $content) {
            $content->header('案例中心');
            $content->description('创建');

            $content->body($this->form());
        });
    }

    protected function grid()
    {
        return Admin::grid(CaseCenter::class, function (Grid $grid) {
            // $grid->position_tags('轮播图序号');
            $grid->id('序号');
            $grid->title('案例中心标题');
            $grid->img('案例中心图片')->image();
            $grid->thumb('案例中心缩略图')->image();
            // $grid->content('案例中心内容');
            $grid->column('content','案例中心内容')->display(function ($content) {
              return $content;
            });
            $grid->disableFilter();
            $grid->disableExport();
            // $grid->disableCreateButton();
            // $grid->disablePagination();
            $grid->disableFilter();
            $grid->paginate(4);
            $grid->perPages([4]);
            $grid->disableRowSelector();
            // $grid->disableCreateButton();
            // $grid->disableActions();
            $grid->actions(function ($actions) {
                // $actions->disableDelete();
                // $actions->disableEdit();
            });
        });
    }

    protected function form()
    {
        return Admin::form(CaseCenter::class, function (Form $form) {
            // $form->text('position_tags', '轮播图位置');
            $form->text('title', '案例中心标题')->rules('required|min:5',[
           'required' => '标题不能为空!',
           'min'   => '标题不能少于5个字符!'
]);;
            $form->image('img', '案例中心图片')->rules('required',[
           'required' => '图片不能为空!'
]);;
            $form->image('thumb', '案例中心缩略图')->help('建议分辨率1920*450')->rules('required',[
           'required' => '缩略图不能为空!'
]);;
            // $form->textarea("content","案例中心内容")->rows(10)->rules('required|min:10');
//             $form->editor("content","案例中心内容")->rules('required',[
//            'required' => '不能为空!'
// ]);
$form->textarea("content","商品简述...")->rows(10);
// $form->select('product_type_id', '产品类型')->options(ProductType::pluck('name', 'id'))->rules('required');
        });
    }
  }
